<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取URL参数</title>
</head>
<body>
    
</body>
</html>
<script>
    function getQueryParams(){
        const result = {};
        const queryString = window.location.search;
        // const queryString = "?name=weishao&age=18"
        // "?name=weishao&age=18"
        const reg = /[?&][^?&]+=[^?&]+/g;
        const found = queryString.match(reg); //['?name=weishao','&age=18']
        if (found) {
            found.forEach(item=>{
                let temp = item.substring(1).split('=');
                let key = temp[0];
                let value = temp[1];
                result[key] = value;
            })
        }
        // return result
        console.log(result);
    }
    getQueryParams()
</script>